<%@page import="java.sql.*" %>
<%@ page import="com.hline.kbcss.MyDriver"%>


<%


PreparedStatement pst=null;

try{ 
   Statement stmt = MyDriver.getConnection("READ");
   ResultSet rs = stmt.executeQuery("select count(*) from hr where uname='"+request.getParameter("uname")+"'");
   int count=0;
   if(rs.next()) {
   	count = rs.getInt(1);
   }
   if(count==0) {
	pst=MyDriver.getPrepare("insert into hr values(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

	System.out.println("taking values");

	
	String fname=request.getParameter("fname");
	String mname=request.getParameter("mname");
	String lname=request.getParameter("lname");
	
		String uare=request.getParameter("lname");
		String sex=request.getParameter("gender");
	    
	    String city=request.getParameter("city");
		String email=request.getParameter("email");
		String phone=request.getParameter("phone");

   String uname=request.getParameter("uname");
   String pswd=request.getParameter("pswd");
   
   String exp1=request.getParameter("years");
   String exp2=request.getParameter("months");
   
   String exp=exp1+"."+exp2;
   String comp=request.getParameter("company");
   String web=request.getParameter("web");
 String[] likes=request.getParameterValues("likes");
   String likes1="";
   if (likes != null) 
   {
      for (int i = 0; i < likes.length; i++) 
      {
		  likes1=likes[i]+","+likes1;
         System.out.println ("<b>"+likes1+"<b>");
      }
   }
out.println("values are"+likes1);
	pst.setString(1,fname);
	pst.setString(2,mname);
	pst.setString(3,lname);
    
	pst.setString(4,uare);
	pst.setString(5,sex);
	
	pst.setString(6,exp);
    pst.setString(7,city);
	 pst.setString(8,comp);
	 pst.setString(9,web);
	pst.setString(10,email);
	pst.setString(11,phone);
	
	pst.setString(12,uname);
	pst.setString(13,pswd);
	pst.setString(14, likes1);
	pst.setInt(15,0);
	System.out.println("values taken");

	int i=pst.executeUpdate();

	System.out.println("values inserted");

	
    
 	 if(i>0)
			 {
	
				response.sendRedirect("index.jsp");
				 
			 }
     
	
			 else
			 {
				 
				response.sendRedirect("userreg.jsp?message=<font color=red>not registered , please try again</font>");
				 
			 }
} else {
				response.sendRedirect("userreg.jsp?message=<font color=red>User Already Exists.</font>");
}
}catch(Exception e){
			  System.out.println(e);
			  e.printStackTrace();
		  }
	

	%>



